package com.jic.manager.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.CmsCategoryMapper;
import com.jic.manager.entity.CmsCategory;
import com.jic.manager.service.CmsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * CMS分类
 * @author : 
 * @email : 
 * @since : 2020-03-04 11:59:27
 * @version : v1.0.0
 */
@Service
public class CmsCategoryServiceImpl implements CmsCategoryService {

    @Autowired
    private CmsCategoryMapper cmsCategoryMapper;

    @Override
    public long insert(CmsCategory cmsCategory) {
        long flag = cmsCategoryMapper.insert(cmsCategory);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return cmsCategoryMapper.delete(id);
    }

    @Override
    public long update(CmsCategory cmsCategory) {
        return cmsCategoryMapper.update(cmsCategory);
    }

    @Override
    public CmsCategory queryByPrimaryKey(Long id){
        return cmsCategoryMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<CmsCategory> query(CmsCategory cmsCategory){
        return cmsCategoryMapper.query(cmsCategory);
    }

    @Override
    public PageResult<CmsCategory> queryPage(CmsCategory cmsCategory, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CmsCategory> list = cmsCategoryMapper.queryPage(startIndex, pageQuery.getLimit(), cmsCategory);
        long count = cmsCategoryMapper.queryPageCount(cmsCategory);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}